package com.briup.ch10;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/11
 * @Description:
 */
//Tread 类，匿名内部类
//Runable 实现类 匿名实现类 lambda
class MyRun implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" "+i);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Test03 {
    public static void main(String[] args) {
        Thread t1=new Thread(new MyRun());
        t1.start();
        Thread t2=new Thread(new MyRun(),"t2线程");
        t2.start();
        new Thread(new MyRun()).start();
        //匿名内部类
        new Thread(new Runnable(){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+" "+i);
                }
            }
        },"t5").start();

        //lambda
        Runnable r2=()->{
            System.out.println(Thread.currentThread().getName());
        };
        new Thread(r2,"t6").start();

        new Thread(()->{
            System.out.println("hello");
        },"t7").start();
    }
}
